home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbscrinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-24  |  8.2 KB  |  261 lines

  1. /************************************************************
  2. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  3.  
  4.                     All Rights Reserved
  5.  
  6. Permission  to  use,  copy,  modify,  and  distribute   this
  7. software  and  its documentation for any purpose and without
  8. fee is hereby granted, provided that the above copyright no-
  9. tice  appear  in all copies and that both that copyright no-
  10. tice and this permission notice appear in  supporting  docu-
  11. mentation,  and  that the names of Sun or MIT not be used in
  12. advertising or publicity pertaining to distribution  of  the
  13. software  without specific prior written permission. Sun and
  14. M.I.T. make no representations about the suitability of this
  15. software for any purpose. It is provided "as is" without any
  16. express or implied warranty.
  17.  
  18. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  19. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  20. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  21. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  23. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  24. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  25. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  
  27. ********************************************************/
  28.  
  29. #include "X.h"
  30. #include "Xmd.h"
  31. #include "servermd.h"
  32. #include "scrnintstr.h"
  33. #include "pixmapstr.h"
  34. #include "resource.h"
  35. #include "colormap.h"
  36. #include "colormapst.h"
  37. #include "cfb.h"
  38. #include "mi.h"
  39. #include "mistruct.h"
  40. #include "dix.h"
  41. #include "cfbmskbits.h"
  42. #include "mibstore.h"
  43.  
  44. extern RegionPtr mfbPixmapToRegion();
  45. extern RegionPtr cfbCopyPlane();
  46. extern Bool mfbAllocatePrivates();
  47.  
  48. extern int defaultColorVisualClass;
  49.  
  50. #define _BP 8
  51. #define _RZ ((PSZ + 2) / 3)
  52. #define _RS 0
  53. #define _RM ((1 << _RZ) - 1)
  54. #define _GZ ((PSZ - _RZ + 1) / 2)
  55. #define _GS _RZ
  56. #define _GM (((1 << _GZ) - 1) << _GS)
  57. #define _BZ (PSZ - _RZ - _GZ)
  58. #define _BS (_RZ + _GZ)
  59. #define _BM (((1 << _BZ) - 1) << _BS)
  60. #define _CE (1 << _RZ)
  61.  
  62. static VisualRec visuals[] = {
  63. /* vid  class        bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
  64. #ifndef STATIC_COLOR
  65.     0,  PseudoColor, _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  66.     0,  DirectColor, _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  67.     0,  GrayScale,   _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  68.     0,  StaticGray,  _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  69. #endif
  70.     0,  StaticColor, _BP,  1<<PSZ,   PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  71.     0,  TrueColor,   _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS
  72. };
  73.  
  74. #define    NUMVISUALS    ((sizeof visuals)/(sizeof visuals[0]))
  75.  
  76. static  VisualID VIDs[NUMVISUALS];
  77.  
  78. static DepthRec depths[] = {
  79. /* depth    numVid        vids */
  80.     1,        0,        NULL,
  81.     8,        NUMVISUALS,    VIDs
  82. };
  83.  
  84. #define NUMDEPTHS    ((sizeof depths)/(sizeof depths[0]))
  85.  
  86. int cfbWindowPrivateIndex;
  87. int cfbGCPrivateIndex;
  88. static unsigned long cfbGeneration = 0;
  89.  
  90. miBSFuncRec cfbBSFuncRec = {
  91.     cfbSaveAreas,
  92.     cfbRestoreAreas,
  93.     (void (*)()) 0,
  94.     (PixmapPtr (*)()) 0,
  95.     (PixmapPtr (*)()) 0,
  96. };
  97.  
  98. /*ARGSUSED*/
  99. static Bool
  100. cfbCloseScreen (index, pScreen)
  101.     int        index;
  102.     ScreenPtr    pScreen;
  103. {
  104.     xfree (pScreen->devPrivate);
  105.     return TRUE;
  106. }
  107.  
  108. /* dts * (inch/dot) * (25.4 mm / inch) = mm */
  109. Bool
  110. cfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
  111.     register ScreenPtr pScreen;
  112.     pointer pbits;        /* pointer to screen bitmap */
  113.     int xsize, ysize;        /* in pixels */
  114.     int dpix, dpiy;        /* dots per inch */
  115.     int width;            /* pixel width of frame buffer */
  116. {
  117.     register PixmapPtr pPixmap;
  118.     int    i;
  119.  
  120.     if (cfbGeneration != serverGeneration)
  121.     {
  122.     /*  Set up the visual IDs */
  123.     for (i = 0; i < NUMVISUALS; i++) {
  124.         visuals[i].vid = FakeClientID(0);
  125.         VIDs[i] = visuals[i].vid;
  126.     }
  127.     cfbGeneration = serverGeneration;
  128.     }
  129.     if (!mfbAllocatePrivates(pScreen,
  130.                  &cfbWindowPrivateIndex, &cfbGCPrivateIndex))
  131.     return FALSE;
  132.     if (!AllocateWindowPrivate(pScreen, cfbWindowPrivateIndex,
  133.                    sizeof(cfbPrivWin)) ||
  134.     !AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
  135.     return FALSE;
  136.     pScreen->width = xsize;
  137.     pScreen->height = ysize;
  138.     pScreen->mmWidth = (xsize * 254) / (dpix * 10);
  139.     pScreen->mmHeight = (ysize * 254) / (dpiy * 10);
  140.     pScreen->numDepths = NUMDEPTHS;
  141.     pScreen->allowedDepths = depths;
  142.  
  143.     pScreen->rootDepth = 8;
  144.     pScreen->minInstalledCmaps = 1;
  145.     pScreen->maxInstalledCmaps = 1;
  146.     pScreen->backingStoreSupport = Always;
  147.     pScreen->saveUnderSupport = NotUseful;
  148.     /* let CreateDefColormap do whatever it wants */ 
  149.     pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
  150.  
  151.     /* cursmin and cursmax are device specific */
  152.  
  153.     pScreen->numVisuals = NUMVISUALS;
  154.     pScreen->visuals = visuals;
  155.  
  156.     pPixmap = (PixmapPtr ) xalloc(sizeof(PixmapRec));
  157.     if (!pPixmap)
  158.     return FALSE;
  159.     pPixmap->drawable.type = DRAWABLE_PIXMAP;
  160.     pPixmap->drawable.depth = 8;
  161.     pPixmap->drawable.pScreen = pScreen;
  162.     pPixmap->drawable.serialNumber = 0;
  163.     pPixmap->drawable.x = 0;
  164.     pPixmap->drawable.y = 0;
  165.     pPixmap->drawable.width = xsize;
  166.     pPixmap->drawable.height = ysize;
  167.     pPixmap->refcnt = 1;
  168.     pPixmap->devPrivate.ptr = pbits;
  169.     pPixmap->devKind = PixmapBytePad(width, 8);
  170.     pScreen->devPrivate = (pointer)pPixmap;
  171.  
  172.     /* anything that cfb doesn't know about is assumed to be done
  173.        elsewhere.  (we put in no-op only for things that we KNOW
  174.        are really no-op.
  175.     */
  176.     pScreen->CreateWindow = cfbCreateWindow;
  177.     pScreen->DestroyWindow = cfbDestroyWindow;
  178.     pScreen->PositionWindow = cfbPositionWindow;
  179.     pScreen->ChangeWindowAttributes = cfbChangeWindowAttributes;
  180.     pScreen->RealizeWindow = cfbMapWindow;
  181.     pScreen->UnrealizeWindow = cfbUnmapWindow;
  182.  
  183.     pScreen->RealizeFont = mfbRealizeFont;
  184.     pScreen->UnrealizeFont = mfbUnrealizeFont;
  185.     pScreen->CloseScreen = cfbCloseScreen;
  186.     pScreen->QueryBestSize = mfbQueryBestSize;
  187.     pScreen->GetImage = cfbGetImage;
  188.     pScreen->GetSpans = cfbGetSpans;
  189.     pScreen->SourceValidate = (void (*)()) 0;
  190.     pScreen->CreateGC = cfbCreateGC;
  191.     pScreen->CreatePixmap = cfbCreatePixmap;
  192.     pScreen->DestroyPixmap = cfbDestroyPixmap;
  193.     pScreen->ValidateTree = miValidateTree;
  194.  
  195. #ifdef    STATIC_COLOR
  196.     pScreen->InstallColormap = cfbInstallColormap;
  197.     pScreen->UninstallColormap = cfbUninstallColormap;
  198.     pScreen->ListInstalledColormaps = cfbListInstalledColormaps;
  199.     pScreen->StoreColors = NoopDDA;
  200. #endif
  201.     pScreen->ResolveColor = cfbResolveColor;
  202.  
  203.     pScreen->RegionCreate = miRegionCreate;
  204.     pScreen->RegionInit = miRegionInit;
  205.     pScreen->RegionCopy = miRegionCopy;
  206.     pScreen->RegionDestroy = miRegionDestroy;
  207.     pScreen->RegionUninit = miRegionUninit;
  208.     pScreen->Intersect = miIntersect;
  209.     pScreen->Inverse = miInverse;
  210.     pScreen->Union = miUnion;
  211.     pScreen->Subtract = miSubtract;
  212.     pScreen->RegionReset = miRegionReset;
  213.     pScreen->TranslateRegion = miTranslateRegion;
  214.     pScreen->RectIn = miRectIn;
  215.     pScreen->PointInRegion = miPointInRegion;
  216.     pScreen->WindowExposures = miWindowExposures;
  217.     pScreen->PaintWindowBackground = cfbPaintWindow;
  218.     pScreen->PaintWindowBorder = cfbPaintWindow;
  219.     pScreen->CopyWindow = cfbCopyWindow;
  220.     pScreen->ClearToBackground = miClearToBackground;
  221.  
  222.     pScreen->RegionNotEmpty = miRegionNotEmpty;
  223.     pScreen->RegionEmpty = miRegionEmpty;
  224.     pScreen->RegionExtents = miRegionExtents;
  225.     pScreen->RegionAppend = miRegionAppend;
  226.     pScreen->RegionValidate = miRegionValidate;
  227.     pScreen->BitmapToRegion = mfbPixmapToRegion;
  228.     pScreen->RectsToRegion = miRectsToRegion;
  229.     pScreen->SendGraphicsExpose = miSendGraphicsExpose;
  230.  
  231.     pScreen->BlockHandler = NoopDDA;
  232.     pScreen->WakeupHandler = NoopDDA;
  233.     pScreen->blockData = (pointer)0;
  234.     pScreen->wakeupData = (pointer)0;
  235.  
  236.     pScreen->CreateColormap = cfbInitializeColormap;
  237.     pScreen->DestroyColormap = NoopDDA;
  238.  
  239.     pScreen->defColormap = FakeClientID(0);
  240.     if (defaultColorVisualClass < 0)
  241.     {
  242.     i = 0;
  243.     }
  244.     else
  245.     {
  246.     for (i = 0;
  247.          (i < NUMVISUALS) && (visuals[i].class != defaultColorVisualClass);
  248.          i++)
  249.         ;
  250.     if (i >= NUMVISUALS)
  251.         i = 0;
  252.     }
  253.     pScreen->rootVisual = visuals[i].vid;
  254.     miInitializeBackingStore (pScreen, &cfbBSFuncRec);
  255.     mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
  256. #ifdef MITSHM
  257.     ShmRegisterFbFuncs(pScreen);
  258. #endif
  259.     return TRUE;
  260. }
  261.